package com.lanxiao.cloud.common.fill;

import cn.hutool.core.collection.CollUtil;
import com.lanxiao.cloud.common.core.dto.BaseDto;
import com.lanxiao.cloud.common.core.dto.UserBaseDto;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import org.springframework.util.Assert;

/**
 * 填充信息处理模型
 * @author ：qiaoliang
 * @date ：2021-04-02
 */
public class FillHandle<T,V,I> extends AbstractFillHandle {

  private final FillType fillType;

  private final List<FillAppointment<T,V>> fillAppointments;

  private final List<Function<T,I>> functions;

  public FillHandle(
      FillType fillType,
      FillAppointment<T, V> fillAppointment,
      Function<T, I> function) {
    this(fillType, Collections.singletonList(fillAppointment), Collections.singletonList(function));
  }

  public FillHandle(FillType fillType,
      List<FillAppointment<T, V>> fillAppointments,
      List<Function<T, I>> functions) {
    Assert.notNull(fillType, "处理类型不能为空!");
    Assert.isTrue(CollUtil.isNotEmpty(fillAppointments), "填充接口不能为空!");
    Assert.isTrue(CollUtil.isNotEmpty(functions), "获取接口不能为空!");
    Assert.isTrue(fillAppointments.size() == functions.size(), "填充接口与获取接口不匹配!");
    this.fillType = fillType;
    this.fillAppointments = fillAppointments;
    this.functions = functions;
  }

  public List<FillAppointment<T, V>> getFillAppointments() {
    return fillAppointments;
  }

  public List<Function<T, I>> getFunctions() {
    return functions;
  }

  @Override
  protected FillType type() {
    return fillType;
  }

}
